package com.diankangwo.factory.controller;

import com.diankangwo.common.annotation.SysLog;
import com.diankangwo.common.utils.Query;
import com.diankangwo.common.utils.R;
import com.diankangwo.factory.entity.TdHomepage;
import com.diankangwo.factory.service.TdHomePageService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 广告bannerController
 */
@RestController
@RequestMapping("/fac/banner")
public class TdBannerController {

    @Autowired
    private TdHomePageService tdHomePageService;

    /**
     * 新增广告banner
     */
    @ApiOperation(value = "新增广告banner", notes = "")
    @ApiImplicitParam(name = "TdHomopage", value = "新增数据", required = true, dataType = "TdHomopage")
    @SysLog("新增广告banner")
    @RequestMapping("/insert")
    @RequiresPermissions("fac:banner:insert")
    public R insert(TdHomepage tdHomepage) {
        if (tdHomepage.getId() == null) {
            tdHomePageService.insert(tdHomepage);
        } else {
            tdHomePageService.updateByPrimaryKey(tdHomepage);
        }

        return R.ok();
    }

    /**
     * 查询广告列表
     */
    @ApiOperation(value = "查询广告列表", notes = "")
    @SysLog("查询广告列表")
    @RequestMapping("/findAll")
    @RequiresPermissions("fac:banner:findAll")
    public R findAll(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<TdHomepage> tdHomopages = tdHomePageService.queryList(query);
        return R.ok().put("homePage", tdHomopages);
    }

    /**
     * 查看详情
     */
    @ApiOperation(value = "", notes = "")
    @SysLog("查看详情")
    @RequestMapping("/findById")
    @RequiresPermissions("fac:banner:findById")
    public R findById(int id) {
        return R.ok().put("homePage", tdHomePageService.selectByPrimaryKey(id));
    }

    /**
     * 编辑
     */
    @ApiOperation(value = "", notes = "")
    @SysLog("update")
    @RequestMapping("/update")
    @RequiresPermissions("fac:banner:update")
    public R update(TdHomepage tdHomepage) {
        tdHomePageService.updateByPrimaryKey(tdHomepage);
        return R.ok();
    }

    /**
     * 删除广告
     */
    @ApiOperation(value = "删除广告", notes = "")
    @SysLog("删除广告")
    @RequestMapping("/delete")
    @RequiresPermissions("fac:banner:delete")
    public R delete(int id) {
        tdHomePageService.deleteByPrimaryKey(id);
        return R.ok();
    }
}
